package com.rwhansen.humidor;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.io.File;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JLabel;

public class CigarDetailUtility {

	private JFrame frmCigarDetailUtility;
	private Database cigarDatabase;
	private String cigarDatabaseFileName;
	private JTextField txtFinished;
	private JTextField textField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CigarDetailUtility window = new CigarDetailUtility();
					window.frmCigarDetailUtility.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public CigarDetailUtility() {
		loadDatabase();
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmCigarDetailUtility = new JFrame();
		frmCigarDetailUtility.setTitle("Cigar Detail Utility");
		frmCigarDetailUtility.setBounds(100, 100, 662, 458);
		frmCigarDetailUtility.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		
		JLabel lblCountry = new JLabel("Country");
		lblCountry.setBounds(89, 144, 46, 14);
		frmCigarDetailUtility.getContentPane().add(lblCountry);
		
		textField = new JTextField();
		textField.setBounds(178, 141, 226, 20);
		frmCigarDetailUtility.getContentPane().add(textField);
		textField.setColumns(10);
		
				
		
		JButton btnRun = new JButton("Run");
		btnRun.setBounds(0, 399, 646, 23);
		btnRun.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Database tempDatabase = new Database(cigarDatabase.getName());

				
				
			
				
				
				
				
				
				
//				for (int i = 0; i < cigarDatabase.getCigars().size(); i++) {
//					Cigar newCigar = new Cigar("");
//					newCigar = cigarDatabase.getCigars().get(i);
//
//					
//					
//					
//
////do not change this part				
//					newCigar.setModified("T");
//					tempDatabase.addCigarToDatabase(newCigar);
//				
//				}
				
				Database.writeDatabase(cigarDatabaseFileName, tempDatabase);
				
//				System.exit(0);
				
			}
		});
		frmCigarDetailUtility.getContentPane().setLayout(null);
		frmCigarDetailUtility.getContentPane().add(btnRun);
		
		
		
		
		
		
		
		
	}
	
	private void loadDatabase() {
//		String cigarDatabaseFileName = Database.CIGAR_DB_FILENAME;
//		cigarDatabaseFileName = "RealCigarDatabase.xml";
//		cigarDatabaseFileName = "RealRatingsDatabase.xml";
//		cigarDatabaseFileName = "RealHumidorDatabase.xml";
		cigarDatabaseFileName = "CigarBrandInformation.xml";
		cigarDatabase = new Database(cigarDatabaseFileName);
		File file1 = new File(cigarDatabaseFileName);
		boolean exists1 = file1.exists();
		if (exists1) {
			cigarDatabase = Database.readDatabase(cigarDatabaseFileName);
		}
	}
}
